# #1、完成字符串的切片
num_str = "0123456789"
# 截取从 2 ~ 5 位置 的字符串
print(num_str[2:5])
# 截取从 2 ~ 末尾的字符串
print(num_str[2:])
# 截取从 开始~ 5 位置 的字符串
print(num_str[:5])
# 截取完整的字符串
print(num_str[:])
# 从开始位置，每隔一个字符截取字符串
print(num_str[::2])
# 从索引 1 开始，每隔一个取一个
print(num_str[1::2])
# 截取从 2 ~ 末尾 - 1的字符串
print(num_str[2::-1])
# 截取字符串末尾两个字符
print(num_str[-2:])
# 字符串的逆序（面试题）
print(num_str[::-1])
# 使用zip组合下面两个元组，变为列表嵌套元组格式，与上课输出效果一致
a = (1, 2, 3)
b = ('a', 'b', 'c')
print(list(zip(a, b)))

# 使用enumerate
# 把seasons = ['Spring', 'Summer', 'Fall', 'Winter'] 变为一个字典
seasons = ['Spring', 'Summer', 'Fall', 'Winter']
for id, value in enumerate(seasons):
    print(id, value)
    mylist = {id: val for id, val in enumerate(seasons)}
    print(mylist)


# 缺省参数和多值参数
def print_info(name, gender=True):
    gender_text = 'man'
    if not gender:
        gender_text = 'woman'
    print("%s 是 %s" % (name, gender_text))


print_info('xiaoming')
print_info('xiaoming', False)
print_info('xiaoming', True)


def print_info1(name, title='', gender=True):
    gender_text = 'man'
    if not gender:
        gender_text = 'woman'
    print("%s%s is %s" % (title, name, gender_text))


print_info1('xiaoming')
print_info1("xiaoming", 'master')
print_info1("xiaoming", gender=False)


def demo(num, num1, *args, **kwargs):
    print(num)
    print(num1)
    print(args)
    print(kwargs)


def main(num, *args, **kwargs):
    demo(num, *args, **kwargs)


main(1, 2, name='xiaoming', age=18)
main(1, 2, age=18)
main(1, 2, 3, 4, 5, name='xiaoming', age=18)
